package com.example.dmgame.activity;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.example.dmgame.R;
import com.example.dmgame.utils.AsyncBitmapLoader;
import com.example.dmgame.utils.AsyncBitmapLoader.ImageCallBack;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class GameContentActivity extends Activity implements OnClickListener{
	TextView gameName,gf_typeName,gf_made_company,gf_release_company,gf_pubdate,gf_website,gonglue,yxpt;
	ImageView imageView;
	Button returnBtn;
	String website;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gamecontent_fragment);
		
		returnBtn = (Button)this.findViewById(R.id.gamecontent_return);
		returnBtn.setOnClickListener(this);
		
		Bundle bundle = getIntent().getBundleExtra("gamecontent");
		String litpic = bundle.getString("litpic");
		String title = bundle.getString("title");
		String made_company = bundle.getString("made_company");
		String release_company = bundle.getString("release_company");
		website = bundle.getString("website");
		String typename = bundle.getString("typename");
		String pubdate = bundle.getString("pubdate");
		String description = bundle.getString("description");
		String terrace = bundle.getString("terrace");
		
		gameName = (TextView)this.findViewById(R.id.gf_gameName);
		gf_typeName = (TextView)this.findViewById(R.id.gf_typename);
		gf_made_company = (TextView)this.findViewById(R.id.made_company);
		gf_release_company = (TextView)this.findViewById(R.id.release_company);
		gf_pubdate = (TextView)this.findViewById(R.id.gf_pubdate);
		gf_website = (TextView)this.findViewById(R.id.gf_website);
		gonglue = (TextView)this.findViewById(R.id.gonglue);
		yxpt = (TextView)this.findViewById(R.id.yxpt);
		
		gf_website.setOnClickListener(this);
		
		Log.i("GameContentActivity", "---title--->>"+title);
		
		imageView = (ImageView)this.findViewById(R.id.gf_imageview);
		
		gameName.setText("游戏名称:"+title);
		gf_typeName.setText("游戏类型:"+typename);
		gf_made_company.setText("开发厂商:"+made_company);
		gf_release_company.setText("发售厂商:"+release_company);
		gf_website.setText("官方网站:"+website);
		SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
		Date date = new Date(Long.parseLong(pubdate));
		gf_pubdate.setText("发售日期:"+format.format(date));
		gonglue.setText("攻略信息:"+description);
		yxpt.setText("游戏平台:"+terrace);
		
		Log.i("GameContentActivity", "---litpic--->>"+litpic);
		AsyncBitmapLoader asyncBitmapLoader = new AsyncBitmapLoader();
		Bitmap bitmap = asyncBitmapLoader.loadBitmap(imageView, "http://www.3dmgame.com"+litpic, new ImageCallBack() {
			
			@Override
			public void imageLoad(ImageView imageView, Bitmap bitmap) {
				// TODO Auto-generated method stub
				imageView.setImageBitmap(bitmap);
			}
		});
		if(bitmap==null){
			imageView.setImageResource(R.drawable.product_default);
		}else{
			imageView.setImageBitmap(bitmap);
		}

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.gamecontent_return:
			finish();
			break;

		case R.id.gf_website:
			Intent intent = new Intent(GameContentActivity.this, WebSiteActivity.class);
			intent.putExtra("website", website);
			startActivity(intent);
		}
		
	}

}
